<template>
  <div class="Header-wrapper">
    <div class="header">
      <!-- logo框 -->
      <router-link class="logoBox" to="/">
        <img src="../assets/logo.png" alt=""/>
      </router-link>
      <!-- 主题 -->
      <div class="header-menu">
        <div class="Header-menu-link">
          <router-link to="/">首页</router-link>
        </div>
        <div class="Header-menu-link">
          <router-link to="all">全部</router-link>
        </div>
      </div>
      <!-- 右侧Box -->
      <div class="rightBox">
        <!--右侧搜索栏-->
        <div class="right_SearchBox">
          <el-input
            placeholder="请搜索"
            size="medium"
            class="search_input"
            v-model="searchParam">
            <i slot="suffix" class="el-icon-search cursor"
               style="margin-right: 6px;"></i>
          </el-input>
        </div>
        <!--右侧头像区域-->
        <div class="right_avatar" v-if="isLogin">
          <el-popover
            placement="bottom"
            width="100"
            trigger="hover">
            <div class="username-Text">{{ userInfo.username }}</div>
            <div class="logout cursor" @click="logout">
              <i class="iconfont icon-tuichu"></i>退出
            </div>
            <div class="random_avatar cursor" slot="reference">
            <span class="avatar_span">
              <img :src="avatarUrl" alt=""/>
            </span>
            </div>
          </el-popover>
        </div>
        <div class="loginText cursor" @click="maskOn" v-if="!isLogin">登录/注册</div>
        <!--上传文件-->
        <a class="link_uploadBtn" @click="toUpload">
          <i class="iconfont icon-shangchuan"></i>
          上传视频
        </a>
      </div>

    </div>
  </div>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: "Header",
  data() {
    return {
      searchParam: "",

    };
  },
  computed: {
    ...mapState({
      isLogin: (state) => state.user.isLogin,
      userInfo: (state) => state.user.userInfo
    }),
    avatarUrl() {
      let api = "https://api.multiavatar.com/";
      let avatarSrc = api + (Math.random() * 10000) + ".svg?apikey=ox4mpMeVQP9fHY";
      this.$store.commit("AVATARSRC", avatarSrc);
      return avatarSrc;
    }
  },
  methods: {
    maskOn() {
      this.$bus.$emit("maskShow");
    },
    async logout() {
      let result = await this.$store.dispatch("logout");
      if (result.code === 200) this.$modal.msgSuccess(result.message);
    },
    toUpload() {
      if (this.isLogin) {
        this.$router.push("/upload");
      } else {
        this.maskOn();
      }
    }
  },
};
</script>

<style lang="less" scoped>
.Header-wrapper {
  background-image: url("../assets/indexBgd.jpeg");
  min-width: 900px;
  width: 100%;
  position: fixed;
  top: 0;
  z-index: 999;

  .header {
    margin: auto;
    width: 1200px;
    height: 60px;
    display: flex;
    line-height: 60px;

    .logoBox {
      width: 70px;
      height: 100%;
      overflow: hidden;

      img {
        height: 100%;
      }
    }

    .header-menu {
      margin-left: 20px;
      display: flex;

      .Header-menu-link {
        margin: 0 4px;

        a {
          width: 56px;
          color: #fff;

          &:hover {
            color: #ff5d23;

            .arrow {
              transform: rotate(180deg);
            }
          }

          display: inline-block;
          vertical-align: middle;
          margin: 12px 0;
          line-height: 36px;
          height: 36px;
          text-align: center;
          font-size: 17px;

          .arrow {
            font-size: 5px;
            display: inline-block;
            transition: 0.5s;
          }
        }
      }
    }

    .rightBox {
      margin-left: auto;
      display: flex;

      /*搜索相关样式*/

      .right_SearchBox {
        margin-right: 30px;

        ::v-deep .search_input > .el-input__inner {
          border-radius: 20px !important;
          width: 142px;
          transition: .3s;

          &:focus {
            width: 176px;
          }
        }
      }

      /*头像相关样式*/

      .right_avatar {
        margin-left: 10px;


        .random_avatar {
          width: 52px;
          padding: 10px 0 10px 10px;

          .avatar_span {
            width: 40px;
            height: 40px;
            display: block;
          }
        }

        /*推出下拉宽*/

        .logout {
          text-align: center;
        }

      }


      /*登录注册字体*/

      .loginText {
        color: white;

        &:hover {
          color: #ff5d23;
        }
      }

      /*文件上传*/

      .link_uploadBtn {
        align-self: center;
        background: #ff5d23;
        color: #ffffff;
        display: inline-block;
        width: 106px;
        height: 32px;
        line-height: 30px;
        text-align: center;
        margin: 0 0 0 20px;
        border-radius: 40px;
        font-size: 14px;
        cursor: pointer;
      }
    }

  }


}


</style>
